package com.dailyblue.java.thread.四个方法;

import lombok.SneakyThrows;

public class DemoD {
    private static Integer i = 1;
    private static Object obj = new Object();

    static class D1 implements Runnable {
        @SneakyThrows
        public void run() {
            synchronized (obj) {
                System.out.println(Thread.currentThread().getName() + "start");
                for (int j = 0; j < 10; j++) {
                    i++;
                    Thread.sleep(100);
                }
                System.out.println(Thread.currentThread().getName() + "end");
            }
        }
    }

    @SneakyThrows
    public static void main(String[] args) {
        D1 d1 = new D1();
        D1 d2 = new D1();
        Thread t1 = new Thread(d1);
        Thread t2 = new Thread(d2);
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println("i:" + i);

    }
}
